package cn.tedu.file;

import java.io.*;

/*本类用于测试字节输入流*/
public class TestIn {
    public static void main(String[] args) {
        method1();//用于测试普通字节输入流FIS
        method2();//用于测试高效字节输入流BufferedInputStream
    }

    private static void method1() {
       //4,定义一个在本方法中都生效的局部变量,注意手动赋值null
        InputStream in=null;
        try { //1,创建流对象
            //InputStream in=new FileInputStream(new File("F:\\ready\\1.txt"));

            in =new FileInputStream("F:\\ready\\1.txt");
       //2,使用对象
            //2.1,定义变量用来保存读到的数据
            int b;
            while ((b=in.read())!=-1){
                System.out.println(b);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            //3,关流
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    //1,创建高效流对象
    private static void method2() {
        InputStream in=null;
        try {
          // InputStream in2=new BufferedInputStream(new FileInputStream(new File("F:\\ready\\1.txt")));
            in=new BufferedInputStream(new FileInputStream("F:\\ready\\1.txt"));
        //2,使用流对象
            int b;
        while ((b=in.read())!=-1){
            System.out.println(b);
        }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            //3,关流
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }


}
